#include <iostream>
#include <unordered_map>
#include <string>
#include <vector>

bool is_prime(int n) {
    if (n < 2) {
        return false;
    }
    for (int i = 2; i*i <= n; i++) {
        if (n % i == 0) {
            return false;
        }
    }
    return true;
}

int nearest_prime(int n) {
    if (n < 2) {
        return -1;
    }
    int i = n;
    while (true) {
        if (is_prime(i)) {
            return i;
        }
        i++;
    }
    return -1;
}

int convert_to_number(std::vector<std::string> words) {
    std::unordered_map<std::string, int> num_dict = {
        {"zero", 0}, {"one", 1}, {"two", 2}, {"three", 3}, {"four", 4},
        {"five", 5}, {"six", 6}, {"seven", 7}, {"eight", 8}, {"nine", 9}
    };
    int num = 0;
    for (const std::string& word : words) {
        num = num * 10 + num_dict[word];
    }
    return num;
}

int main() {
    std::vector<std::string> input_words;
    std::string word;
    std::cout << "Enter three words separated by spaces: ";
    while (input_words.size() < 3 && std::cin >> word) {
        input_words.push_back(word);
    }

    if (input_words.size() != 3) {
        std::cout << "Wrong input" << std::endl;
    } else {
        try {
            int num = convert_to_number(input_words);
            if (num < 100 || num >= 1000) {
                std::cout << "Wrong input" << std::endl;
            } else {
                int nearest = nearest_prime(num);
                std::cout << nearest << std::endl;
            }
        } catch (const std::out_of_range& e) {
            std::cout << "Wrong input" << std::endl;
        }
    }

    return 0;
}
